import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Group {

    private List<Student> students;

    private Random random;



    public Group() {

        this.students = new ArrayList<>();

        this.random = new Random();

    }



    public void addStudent(Student student) {

        if (student == null) {

            throw new IllegalArgumentException("学生不能为空");

        }

        students.add(student);

    }



    public Student getRandomStudent() {

        if (students.isEmpty()) {

            throw new IllegalStateException("组内没有学生");

        }

        int index = random.nextInt(students.size());

        return students.get(index);

    }



    public List<Student> getStudents() {

        return new ArrayList<>(students);  // 返回学生列表的副本

    }



    // 显示所有学生信息

    public void displayAllStudents() {

        System.out.println("\n所有学生信息：");

        for (Student student : students) {

            System.out.printf("姓名：%-8s 班级：%-4s 学号：%-12s 总分：%d%n",

                    student.getName(),

                    student.getClassName(),

                    student.getStudentId(),

                    student.getTotalScore());

        }

    }

}
